

<?php
/**
 * @author Maxi
 */



class Market{
    //private variables
    private $id;
    private $name = "";
    private $street = "";
    private $houseNumber = "";
    private $postal = "";
    private $city = "";
    private $country = "";

    private $db;

    public function __construct($id){
        $this->db = new Database();

        //Überprüfen, ob die Tabelle "market" in der Datenbank existiert. Falls nicht, wird diese angelegt
        if (!$this->db->tableExists("market")){
            $arrFields = array("name", "street", "houseNumber", "postal", "city", "country");
            $arrTypes = array("text", "text", "text", "text", "text", "text");
            echo($this->db->createTable("market", $arrFields, $arrTypes));
        }

        //Objekt mit seinen Werten füllen. Gibt es das Objekt noch nicht, so bleiben die Einträge leer und id erhält den Übergabeparameter
        $res = $this->db->query("SELECT * IN market WHERE id=".$id);
        if($res->num_rows > 0){
            $row = $res->fetch_object();
            $this->id = $id;
            $this->name = $row->name;
            $this->street = $row->street;
            $this->houseNumber = $row->houseNumber;
            $this->postal = $row->postal;
            $this->city = $row->city;
            $this->country = $row->country;
        }
    }

    public function getID(){
        return ($this->id);
    }

    public function getName(){
        return $this->name;
    }

    public function getStreet(){
        return $this->street;
    }

    public function getHouseNumber(){
        return $this->houseNumber;
    }

    public function getPostal(){
        return $this->postal;
    }

    public function getCity(){
        return $this->city;
    }

    public function getCountry(){
        return $this->country;
    }



}

?>
